package xuegao.study.mall.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * spring cloud gateway配置
 */
@Configuration
public class GateWayConfig {

    /**
     * 路由配置->可以在配置文件配置路由,也可以在java bean中添加路由,java bean中的配置可以覆盖配置文件中的配置
     * @param builder
     * @return
     */
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) {
        RouteLocatorBuilder.Builder routes = builder.routes();
        routes
                //后台管理界面
                .route("study-mall-admin", r-> r.path("/admin/**").uri("lb://study-mall-admin"))
                //前台app接口
                .route("study-web-service", r-> r.path("/portal/**").uri("lb://study-web-service"))
                //oauth2认证服务
                .route("study-oauth2-service", r -> r.path("/oauth2/**", "/oauth/**").uri("lb://study-oauth2-service"))
                //订单服务
                .route("study-order-service", r -> r.path("/oms/**").uri("lb://study-order-service"))
                //角色权限服务
                .route("study-rbac-service", r -> r.path("/rbac/**").uri("lb://study-rbac-service"))
                //文件服务
                .route("study-file-service", r-> r.path("/admin/file/**").uri("lb://study-file-service"))
                //答题服务
                .route("ask-sys-service", r-> r.path("/api/v1/**").uri("lb://ask-sys-service"));
        return routes.build();
    }
}
